from django.db import models


# Create your models here.
class Category(models.Model):
    title = models.CharField(verbose_name="类别", unique=True, max_length=30)

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "类别"
        verbose_name_plural = "类别"


class Books(models.Model):
    title = models.CharField(verbose_name='书名', unique=True, max_length=30)
    synopsys = models.CharField(verbose_name='简介', max_length=500)

    def __str__(self):
        return self.title


    class Meta:
        verbose_name = '书'
        verbose_name_plural = '书'


class Book(models.Model):
    title = models.CharField(verbose_name="book", unique=True, max_length=20)
    category = models.ForeignKey(to="Category", on_delete=models.CASCADE)

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "书籍"
        verbose_name_plural = "书籍"


class Ads(models.Model):
    title = models.CharField(verbose_name="轮播图", unique=True, max_length=30)
    url = models.URLField(verbose_name='图片连接地址', unique=True)
    img = models.ImageField(verbose_name="图片", upload_to="ads/")

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "轮播图"
        verbose_name_plural = "轮播图"
